package chapter1.fundamentals.exercise;

import edu.princeton.cs.algs4.StdOut;

/**
 * @author quanlinlin on 2018/10/25 20:02.
 * @version 1.0
 */
public class E_7 {

    public static void main(String[] args) {
        //ea();
        //eb();
        test();
        ec();
    }

    public static void ea() {
        double t = 9.0;
        while (Math.abs(t - 9.0 / t) > .001) {
            System.out.println(t);
            t = (9.0 / t + t) / 2.0;
        }
        StdOut.printf("%.5f\b", t);
    }

    public static void eb() {
        int sum = 0;
        for (int i = 1; i < 1000; i++) {
            for (int j = 0; j < i; j++) {
                sum++;
            }
        }
        System.out.println(sum);
    }

    public static void test() {
        int sum = 0;
        for (int i = 1; i < 1000; i++) {
            sum += i * (1000 - i);
        }
        System.out.println(sum);
    }

    public static  void ec() {
        int sum = 0;
        for (int i = 1; i < 1000; i *= 2) {
            for (int j = 0; j < 1000; j++) {
                sum++;
            }
        }
        System.out.println(sum);
    }
}
